package com.bw.module_cashier.view

import android.graphics.Color
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.bw.module_cashier.R
import com.bw.module_cashier.adapter.CashierPayerAdapter
import com.bw.module_cashier.databinding.ActivityCashierBinding
import com.bw.module_cashier.viewmodel.CashierViewModel
import dagger.hilt.android.AndroidEntryPoint

/**
 * 智慧园区-05-收银台V1.1-20250507
 */
@AndroidEntryPoint
@Route(path = RouterPath.PATH_CASHIER_ACTIVITY)
class CashierActivity : BaseActivity<ActivityCashierBinding>() {
    private val vm by lazy { ViewModelProvider(this)[CashierViewModel::class.java] }
    private val cashierPayerAdapter by lazy { CashierPayerAdapter() }
    override fun initView() {

        mDataBinding.rv.adapter = cashierPayerAdapter
        mDataBinding.rv.layoutManager = LinearLayoutManager(this)
        mDataBinding.month.setOnClickListener {
            cashierPayerAdapter.data.clear()
            cashierPayerAdapter.notifyDataSetChanged()
            mDataBinding.month.setBackgroundColor(Color.parseColor("#1890FF"))
            mDataBinding.month.setTextColor(Color.parseColor("#ffffff"))
            mDataBinding.year.setBackgroundColor(Color.parseColor("#F5F5F5"))
            mDataBinding.year.setTextColor(Color.parseColor("#4B5563"))
        }
        mDataBinding.year.setOnClickListener {
            vm.getCashier(1)
            mDataBinding.year.setBackgroundColor(Color.parseColor("#1890FF"))
            mDataBinding.year.setTextColor(Color.parseColor("#ffffff"))
            mDataBinding.month.setBackgroundColor(Color.parseColor("#F5F5F5"))
            mDataBinding.month.setTextColor(Color.parseColor("#4B5563"))
        }
        vm.getCashier(1)
        cashierPayerAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build(RouterPath.PATH_BILL_ACTIVITY).withSerializable("cashierPayerEntity",cashierPayerAdapter.data[position]).navigation()
        }

        vm.cashierPayerSuccess.observe(this){
            cashierPayerAdapter.data.clear()
            cashierPayerAdapter.data.addAll(it)
            cashierPayerAdapter.notifyDataSetChanged()
        }
        mDataBinding.imageView.setOnClickListener {
            finish()
        }

    }

    override fun getLayoutId(): Int = R.layout.activity_cashier

}